package com.example.tang.zhayan.ui;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.tang.zhayan.R;
import com.obsessive.zbar.CaptureActivity;
import com.squareup.picasso.Picasso;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * Created by yang on 2015/12/19.
 */

@ContentView(R.layout.activity_setting_personally)
public class SettingPersonallyActivity extends AppCompatActivity implements View.OnClickListener {

    @ViewInject(R.id.iv_back)
    private ImageView iv_back;

    @ViewInject(R.id.iv_icon)
    private ImageView iv_icon;

    @ViewInject(R.id.tv_nick_name)
    private TextView tv_nick_name;

    @ViewInject(R.id.rl_find)
    private RelativeLayout rl_find;

    private SharedPreferences preferences;
    private String icon;
    private String userName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        preferences = getSharedPreferences("userMsg", Context.MODE_PRIVATE);
        icon = preferences.getString("icon", "");
        userName = preferences.getString("userName", "");
        initView();
    }

    private void initView() {
        iv_back.setOnClickListener(this);
        rl_find.setOnClickListener(this);
        if (TextUtils.isEmpty(icon) || TextUtils.isEmpty(userName)) {
            Toast.makeText(this, "您还没登录呢", Toast.LENGTH_SHORT).show();
        } else {
            Picasso.with(this).load(icon).placeholder(R.mipmap.default_loader_image1).into(iv_icon);
            tv_nick_name.setText("昵称：" + userName);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.rl_find://扫描二维码
                Intent intent = new Intent(this, CaptureActivity.class);
                startActivity(intent);
                break;
        }
    }
}
